package com.fgou.springcloud.controller;


import com.fgou.springcloud.pojo.Dept;
import com.fgou.springcloud.service.Dept.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 99
 */
@RestController
@RequestMapping(value = "/consumer/dept",produces = "application/json; charset=UTF-8")

public class DeptConsumerController {

    @Qualifier("com.fgou.springcloud.service.Dept.DeptClientService")
    @Autowired
    DeptClientService deptClientService;

    @GetMapping("/list")
    public List<Dept> getDeptAll() {
        return deptClientService.getDeptAll();
    }

    @GetMapping("/get/{id}")
    public Dept getDeptById(@PathVariable(value = "id") Long id) {
        Dept deptById = deptClientService.getDeptById(id);
        if (deptById==null){
            throw new RuntimeException();
        }
        return deptById;
    }

    @PostMapping(value = "/add")
    public Boolean addDeptOne(@RequestBody Map<String, String> map) {
        System.out.println(map.get("deptName"));
        return deptClientService.addDeptOne(map);
    }
}
